<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var num = 10;
        var obj = {
            num: 20
        };
        obj.fn = (function(num) {
            this.num = num * 3; // window.num = 20 * 3 ==> 60(全局的) 
            num++; // mun ++ ==> 21 一定要明白这里的 num 是基本数据类型 和 obj.num没有一点关系的
            return function(n) {
                this.num += n;
                num++;
                console.log(num);
            }
        })(obj.num);
        var fn = obj.fn;
        fn(5); // window.num + 5 ==> 65 num++ ==> 22 输出22
        obj.fn(10); //obj.mun + 10 ==> 20 + 10 ==> 30 num++ ==> 23 输出23
        console.log(num, obj.num); // 65 30
    </script>
</body>

</html>